package com.ruoyi.common.utils;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DmsUtils {

    public static List<Map<String,String>> matchValue(String oldValue){
        Pattern p = Pattern.compile("\\$\\{(.+?)\\}");
        Matcher m = p.matcher(oldValue);
        List<Map<String,String>> res = new ArrayList<>();
        while(m.find())
        {
            Map<String,String> temp = new HashMap<>();
            temp.put(m.group(0),m.group(1));
            res.add(temp);
        }
        return res;
    }

    public static String newValue(String oldValue,List<Map<String,String>> values){
        for (Map<String,String> value:
             values) {
            for (Map.Entry<String,String> entry:
                 value.entrySet()) {
                oldValue.replace(entry.getKey(),entry.getValue());
            }
        }
        return null;
    }

//    public static void main(String[] args) {
//        List<Map<String,String>> res = matchValue("name: ${123} value:${1234}");
//
//        String result = newValue("name: ${123} value:${1234}",res);
//        System.out.println(result);
//    }
}
